// pages/blindHome/blindHome.js
// pages/freeRideHome/freeRideHome.js
//引用
var fileData = require('../../utils/data.js');
var main = require('../../utils/main.js');
const util = require('../../utils/util.js')
var app = getApp();

Page({
  /**
   * 页面的初始数据
   */
  data: {
    httpApiImg: app.globalData.httpApiImg,
    userInfo: '',
    banner_url: [],
    bottabData: app.globalData.bottabDataForXq,
    interval: 3000,
    duration: 1000,
    vertical: false,
    indicatordots: true,
    autoplay: true,
    indicatored: '#F08631',
    indicator: '#fff',
    imageUrl: app.globalData.imageUrl,
    curNavId: 1,
    curIndex: 0,
    // advert_url: fileData.getAdvertData(),
    actiItem: [],
    bannerAdvert: [],
    page: 1,
    charmStarList:[],
    loadSuccess: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    main.changeInput.apply(this, []);
    fileData.getBannerData.apply(this, ['7', 'top', 0, 'banner_url']);
    fileData.getBannerData.apply(this, ['7', 'top', 1, 'bannerAdvert']);
    this.setData({
      userInfo: JSON.parse(wx.getStorageSync('userInfo')),
      ['bottabData[0].current']: true
    })
    wx.showLoading({})
    this.getSeachData();
  },
  switchBotab(e) {
    if (e.currentTarget.dataset.index != 0) {
      wx.navigateTo({
        url: e.currentTarget.dataset.url
      })
    }
  },
  getSeachData() {
    var that=this;
    wx.request({
      url: app.globalData.httpApiCar + 'xqUserBasicInfo/XQhomePage', //仅为示例，并非真实的接口地址
      method: 'POST',
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 默认值
      },
      data: { userId: this.data.userInfo.id, openId: 0 },
      success: function (res) {
        if (res.data.success){
          wx.hideLoading();
          that.setData({
            loadSuccess: true
          })
          that.setData({
            actiItem:res.data.data.pp,
            charmStarList: res.data.data.charmStarList,
          })
        }
      }
    })
  },
  setLove: function (e) {//设置取消心动
    var item = e.currentTarget.dataset.item;
    var that = this;
    wx.request({
      url: app.globalData.httpApiCar + 'xqUserBasicInfo/updateXqUserCharmValue', //仅为示例，并非真实的接口地址
      method: 'POST',
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 默认值
      },
      data: {
        userId: this.data.userInfo.id,
        loveFlag: item.loveFlag == 'Y' ? 'N' : 'Y',
        otherId: item.userId
      },
      success: function (res) {
        if (res.data.success) {
          that.setData({
            ['actiItem[' + e.currentTarget.dataset.index + '].loveFlag']: item.loveFlag == 'Y' ? 'N' : 'Y'
          })
        }
        else {
          wx.showToast({
            title: res.data.error,
            icon: 'none',
            duration: 2000
          })
        }
      }
    })
  },
  leaveWord: function (e) {//留言
    var item = e.currentTarget.dataset.item;
    wx.navigateTo({
      url: '/pages/blindDetail/blindDetail?isLeave=true&id=' + item.id + '&userId=' + item.userId
    })
  },
  showDetail: function (e) {//查看详情
    var item = e.currentTarget.dataset.item;
    wx.navigateTo({
      url: '/pages/blindDetail/blindDetail?id=' + item.id + '&userId=' + item.userId
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },
  switchTap: function (e) {
    wx.navigateTo({
      url: e.currentTarget.dataset.url
    })
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    wx.showNavigationBarLoading(); //在标题栏中显示加载
    this.setData({
      page: 1
    })
    this.getSeachData(true);
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },
})